package com.cs.framework.jdbc.mybatis3.exception;

import com.cs.framework.common.exception.CSRuntimeException;

/**
 * MyBatis异常协助者
 * 
 * @author hedongzhou
 * 
 */
public class MyBatisExceptionHelper {

	/**
	 * MyBatis异常信息封装对象
	 */
	private final static MyBatisExceptionMessage myBatisExceptionMessage = new MyBatisExceptionMessage();

	/**
	 * 获取MyBatis异常信息封装对象
	 * 
	 * @return
	 */
	public static MyBatisExceptionMessage getMessage() {
		return myBatisExceptionMessage;
	}

	/**
	 * 抛出MyBatis异常
	 * 
	 * @param code
	 *            异常信息编号
	 */
	public static void throwJdbcException(String code) {
		throw new CSRuntimeException(myBatisExceptionMessage, code);
	}

	/**
	 * 抛出MyBatis异常
	 * 
	 * @param code
	 *            异常信息编号
	 * @param params
	 *            异常信息动态内容
	 */
	public static void throwJdbcException(String code, Object... params) {
		throw new CSRuntimeException(myBatisExceptionMessage, code, params);
	}

	/**
	 * 抛出MyBatis异常
	 * 
	 * @param cause
	 *            异常原因
	 * @param code
	 *            异常信息编号
	 * @param params
	 *            异常信息动态内容
	 */
	public static void throwJdbcException(Throwable cause, String code, Object... params) {
		throw new CSRuntimeException(cause, myBatisExceptionMessage, code, params);
	}

}
